#!/bin/bash

pwd=$(pwd)

# 插件
apt-get -y install libpcre3 libpcre3-dev libpcrecpp0v5 libssl-dev zlib1g-dev
apt-get -y install build-essential
apt-get -y install libtool
apt-get -y install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

# mariadb10.4
sudo apt-get -y install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.4/ubuntu bionic main'
sudo apt -y update
sudo apt -y install mariadb-server
\cp /etc/my.cnf /etc/my.cnf.bk
\cp mariadb_my.cnf /etc/my.cnf
chmod -R 644 /etc/my.cnf
/etc/init.d/mysql restart
mysql  -uroot  -p <<EOF
grant all privileges on vrcwallet.* to 'brs'@'127.0.0.1' identified by '123456';
grant all privileges on vrcwallet.* to 'brs'@'localhost' identified by '123456';
grant all privileges on vrcpool.* to 'brs'@'127.0.0.1' identified by '123456';
grant all privileges on vrcpool.* to 'brs'@'localhost' identified by '123456';
flush privileges;
create database vrcwallet;
create database vrcpool;
flush privileges;
exit
EOF

# php
apt install -y php7.2-cli
apt install -y php7.2-dev
# 查看php-fpm版本  sudo apt-cache search php-fpm
apt install -y php7.2-fpm
apt install -y php7.2-mysql php7.2-fpm php7.2-curl php7.2-xml php7.2-gd php7.2-mbstring php-memcached php7.2-zip
sed -i 's#^listen = /run/php/php7.2-fpm.sock*#listen = 127.0.0.1:9000#g'  /etc/php/7.2/fpm/pool.d/www.conf
chmod 777 /run/php/php7.2-fpm.sock
# 网页 /etc/php/7.2/fpm/php.ini  cli /etc/php/7.2/cli/php.ini
sed -i 's#^short_open_tag = Off*#short_open_tag = On#g'  /etc/php/7.2/fpm/php.ini  # 网页启用fpm（NGINX解析PHP用）
sed -i 's#^short_open_tag = Off*#short_open_tag = On#g'  /etc/php/7.2/cli/php.ini  # 终端模式启用cli
/etc/init.d/php7.2-fpm restart



# memcached
apt install -y memcached
memcached -d -m 128 -p 11111 -u root

mkdir -p /usr/local/memcached
apt install -y git
git clone https://github.com/php-memcached-dev/php-memcached.git
cd php-memcached/
phpize
apt install -y pkg-config
apt-get install -y zlib1g.dev

./configure --disable-memcached-sasl
make -j24
make install
php --ini
#echo "extension= \"memcached.so\"" >> /etc/php/7.2/fpm/php.ini
#echo "extension= \"memcached.so\"" >> /etc/php/7.2/cli/php.ini

cd $pwd
#nginx
source ./nginx.sh

